unit data;

interface

uses
  SysUtils, Classes, IniFiles, DB, DBXpress, SqlExpr;

type
  TDataMain = class(TDataModule)
  private
    FIterationCount: Integer;
    procedure LoadConnectionSettings(Connection: TSQLConnection);
  public
    procedure SetOldDriverLibrary(const FileName: string);
    procedure SetNewDriverLibrary(const FileName: string);
    procedure SetConnecionParams(Params: TStrings);
    function GetConnecionParams: TStrings;
    property IterationCount: Integer read FIterationCount write FIterationCount;
  published
    connectionNew: TSQLConnection;
    connectionOld: TSQLConnection;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  end;

var
  DataMain: TDataMain;

implementation

uses TestBase;

{$R *.dfm}

{ TDataMain }

procedure TDataMain.DataModuleCreate(Sender: TObject);
begin
  {LoadConnectionSettings(connectionOld);
  connectionOld.LibraryName := IniFile.ReadString('drivers', 'old', 'lxdbexpinf.dll.old');}
  LoadConnectionSettings(connectionNew);
  connectionNew.LibraryName := IniFile.ReadString('drivers', 'new', 'lxdbexpinf.dll');
  FIterationCount := IniFile.ReadInteger('general', 'iterationcount', 5);
end;

procedure TDataMain.DataModuleDestroy(Sender: TObject);
var
  I: Integer;
  Name: string;
begin
  IniFile.WriteInteger('general', 'iterationcount', FIterationCount);
  for I := 0 to GetConnecionParams.Count - 1 do
  begin
    Name := GetConnecionParams.Names[I];
    IniFile.WriteString('connection', Name, GetConnecionParams.Values[Name]);
  end;
  IniFile.WriteString('drivers', 'old', connectionOld.LibraryName);
  IniFile.WriteString('drivers', 'new', connectionNew.LibraryName);
end;

procedure TDataMain.LoadConnectionSettings(Connection: TSQLConnection);
begin
  Connection.DriverName := 'INFORMIXLUXENA';
  Connection.GetDriverFunc := 'getInformixDriver';
  Connection.VendorLib := 'isqlt09a.dll';
  IniFile.ReadSectionValues('connection', Connection.Params);
end;

procedure TDataMain.SetNewDriverLibrary(const FileName: string);
begin
  connectionNew.Close;
  connectionNew.LibraryName := FileName;
end;

procedure TDataMain.SetOldDriverLibrary(const FileName: string);
begin
  connectionOld.Close;
  connectionOld.LibraryName := FileName;
end;

procedure TDataMain.SetConnecionParams(Params: TStrings);
begin
  connectionOld.Close;
  connectionNew.Close;
  connectionOld.Params.Assign(Params);
  connectionNew.Params.Assign(Params);
end;

function TDataMain.GetConnecionParams: TStrings;
begin
  Result := connectionNew.Params;
end;

end.
